using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Adex
{
    /// <summary>
    /// Controller class for tblHistoricalDataForNewCommercial
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class TblHistoricalDataForNewCommercialController
    {
        // Preload our schema..
        TblHistoricalDataForNewCommercial thisSchemaLoad = new TblHistoricalDataForNewCommercial();
        private string userName = String.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}
					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}
				}
				return userName;
            }
        }
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public TblHistoricalDataForNewCommercialCollection FetchAll()
        {
            TblHistoricalDataForNewCommercialCollection coll = new TblHistoricalDataForNewCommercialCollection();
            Query qry = new Query(TblHistoricalDataForNewCommercial.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public TblHistoricalDataForNewCommercialCollection FetchByID(object Id)
        {
            TblHistoricalDataForNewCommercialCollection coll = new TblHistoricalDataForNewCommercialCollection().Where("ID", Id).Load();
            return coll;
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public TblHistoricalDataForNewCommercialCollection FetchByQuery(Query qry)
        {
            TblHistoricalDataForNewCommercialCollection coll = new TblHistoricalDataForNewCommercialCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object Id)
        {
            return (TblHistoricalDataForNewCommercial.Delete(Id) == 1);
        }
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object Id)
        {
            return (TblHistoricalDataForNewCommercial.Destroy(Id) == 1);
        }
        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(int UserID,int? CompanyCode,string UserName,string Product,string Version,string LaunchDay,string Duration,string Sector,string SubSector,string Category,string Advertiser,string Agency,string MediaType1,string FirstAppearance,string EstimatedHours1,string ProgramName1,string MediaType2,string SecondAppearance,string EstimatedHours2,string ProgramName2,string MediaType3,string ThirdAppearance,string EstimatedHours3,string ProgramName3,string Comments,string UploadCommercial,string GenerateId)
	    {
		    TblHistoricalDataForNewCommercial item = new TblHistoricalDataForNewCommercial();
		    
            item.UserID = UserID;
            
            item.CompanyCode = CompanyCode;
            
            item.UserName = UserName;
            
            item.Product = Product;
            
            item.Version = Version;
            
            item.LaunchDay = LaunchDay;
            
            item.Duration = Duration;
            
            item.Sector = Sector;
            
            item.SubSector = SubSector;
            
            item.Category = Category;
            
            item.Advertiser = Advertiser;
            
            item.Agency = Agency;
            
            item.MediaType1 = MediaType1;
            
            item.FirstAppearance = FirstAppearance;
            
            item.EstimatedHours1 = EstimatedHours1;
            
            item.ProgramName1 = ProgramName1;
            
            item.MediaType2 = MediaType2;
            
            item.SecondAppearance = SecondAppearance;
            
            item.EstimatedHours2 = EstimatedHours2;
            
            item.ProgramName2 = ProgramName2;
            
            item.MediaType3 = MediaType3;
            
            item.ThirdAppearance = ThirdAppearance;
            
            item.EstimatedHours3 = EstimatedHours3;
            
            item.ProgramName3 = ProgramName3;
            
            item.Comments = Comments;
            
            item.UploadCommercial = UploadCommercial;
            
            item.GenerateId = GenerateId;
            
	    
		    item.Save(UserName);
	    }
    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int Id,int UserID,int? CompanyCode,string UserName,string Product,string Version,string LaunchDay,string Duration,string Sector,string SubSector,string Category,string Advertiser,string Agency,string MediaType1,string FirstAppearance,string EstimatedHours1,string ProgramName1,string MediaType2,string SecondAppearance,string EstimatedHours2,string ProgramName2,string MediaType3,string ThirdAppearance,string EstimatedHours3,string ProgramName3,string Comments,string UploadCommercial,string GenerateId)
	    {
		    TblHistoricalDataForNewCommercial item = new TblHistoricalDataForNewCommercial();
	        item.MarkOld();
	        item.IsLoaded = true;
		    
			item.Id = Id;
				
			item.UserID = UserID;
				
			item.CompanyCode = CompanyCode;
				
			item.UserName = UserName;
				
			item.Product = Product;
				
			item.Version = Version;
				
			item.LaunchDay = LaunchDay;
				
			item.Duration = Duration;
				
			item.Sector = Sector;
				
			item.SubSector = SubSector;
				
			item.Category = Category;
				
			item.Advertiser = Advertiser;
				
			item.Agency = Agency;
				
			item.MediaType1 = MediaType1;
				
			item.FirstAppearance = FirstAppearance;
				
			item.EstimatedHours1 = EstimatedHours1;
				
			item.ProgramName1 = ProgramName1;
				
			item.MediaType2 = MediaType2;
				
			item.SecondAppearance = SecondAppearance;
				
			item.EstimatedHours2 = EstimatedHours2;
				
			item.ProgramName2 = ProgramName2;
				
			item.MediaType3 = MediaType3;
				
			item.ThirdAppearance = ThirdAppearance;
				
			item.EstimatedHours3 = EstimatedHours3;
				
			item.ProgramName3 = ProgramName3;
				
			item.Comments = Comments;
				
			item.UploadCommercial = UploadCommercial;
				
			item.GenerateId = GenerateId;
				
	        item.Save(UserName);
	    }
    }
}
